<template>
	<view>
		<Header>个人年度履职报告</Header>
		<view class="feedback-form" style="margin: 0px 30px;">
			<uni-forms>
				<uni-forms-item>
					<view class="label">
						<image src="https://zhzx.on-line-demo.com/image/fkbt.png" mode="heightFix"
							style="width: 16px;height: 16px;;margin-right: 10px;"></image>
						标题：
					</view>
					<view class="title">
						<uni-easyinput type="textarea" maxlength="-1" autoHeight v-model="formData.title" :clearable="false"
							placeholder="请输入" />
					</view>
				</uni-forms-item>
				<uni-forms-item>
					<view class="label">
						<image src="https://zhzx.on-line-demo.com/image/xxsm.png" mode="heightFix"
							style="width: 16px;height: 16px;margin-right: 10px;"></image>
						内容：
					</view>
					<uni-easyinput class="content" type="textarea" maxlength="-1" autoHeight v-model="formData.content"
						placeholder="请输入"></uni-easyinput>
				</uni-forms-item>
			</uni-forms>
			<button type="primary" class="btn delete" @click="onSubmit()">保存我的年度履职报告</button>
		</view>
	</view>
</template>

<script>
	import request from '../../common/request.js'
	import Header from '../../components/header.vue'
	export default {
		components: {
			Header
		},
		data() {
			return {
				formData: {
					title: '',
					content: '',
				},
				timeout: null,
			}
		},
		beforeDestroy() {
			if (this.timeout) {
				clearTimeout(this.timeout)
			}
		},
		mounted() {

		},
		methods: {
			onSubmit() {
				if (!this.formData.title) {
					uni.showToast({
						title: '标题不能为空',
						icon: 'none',
						duration: 2000
					});
					return false
				}
				if (!this.formData.content) {
					uni.showToast({
						title: '内容不能为空',
						icon: 'none',
						duration: 2000
					});
					return false
				}

				request({
					url: '/Lvreport/addReport',
					data: this.formData,
					method: 'POST'
				}).then(res => {
					if (res.code == 1) {
						uni.showToast({
							title: res.msg,
							icon: 'none',
							duration: 2000
						});
						uni.$emit('reloadReport')
						this.timeout = setTimeout(() => {
							uni.navigateBack(-1)
						}, 2000)
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none',
							duration: 2000
						});
					}
				})
			},

		}
	}
</script>

<style lang="scss" scoped>
	.feedback-form {
		padding: 30px 0px 20px;
	}

	.label {
		font-size: 16px;
		display: flex;
		align-items: center;
		margin-bottom: 15px;
	}

	.btn {
		margin-bottom: 15px;
		font-size: 14px;
		padding: 5px;
		border-radius: 8px;
	}

	.btn.delete {
		background-color: #ea5c55;
		margin-top: 60px;
	}
</style>